<template>
    <div class="login-container">
        <!-- 背景网格 -->
        <div class="grid-background"></div>

        <!-- 动态光效 -->
        <div class="light-effect"></div>

        <div class="login-box">
            <!-- 标题部分 -->
            <div class="title-section">
                <div class="tech-circle"></div>
                <h2 class="title">
                    <span class="title-text">系统登录</span>
                    <div class="title-line"></div>
                </h2>
                <p class="subtitle">欢迎回来，请登录您的账号</p>
            </div>

            <!-- 登录表单 -->
            <form class="login-form" @submit.prevent="handleLogin">
                <div class="input-group">
                    <!-- 用户名输入框 -->
                    <div class="input-wrapper">
                        <div class="input-border">
                            <input
                                v-model="dataForm.username"
                                type="text"
                                class="input-field"
                                placeholder="用户名"
                            />
                            <div class="input-icon">
                                <div class="icon-circle"></div>
                                <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                                </svg>
                            </div>
                        </div>
                    </div>

                    <!-- 密码输入框 -->
                    <div class="input-wrapper">
                        <div class="input-border">
                            <input
                                v-model="dataForm.password"
                                type="password"
                                class="input-field"
                                placeholder="密码"
                            />
                            <div class="input-icon">
                                <div class="icon-circle"></div>
                                <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
                                </svg>
                            </div>
                        </div>
                    </div>

                    <div class="input-wrapper" style='display: flex;'>
                        <div class="input-border" style='width: 70%'>
                            <input
                                v-model="dataForm.captcha"
                                class="input-field"
                                placeholder="验证码"
                            />
                        </div>
                        <img class='kaptcha' :src="captchaPath" @click="getCaptcha()" alt="">
                    </div>

                </div>

                <!-- 记住我和忘记密码 -->
                <div class="form-options">
                    <div class="remember-me">
                        <label class="custom-checkbox">
                            <input type="checkbox" id="remember-me">
                            <span class="checkmark"></span>
                            <span class="checkbox-label">记住我</span>
                        </label>
                    </div>
                    <a href="#" class="forgot-password">
                        忘记密码？
                    </a>
                </div>

                <!-- 登录按钮 -->
                <button type="submit" class="login-button" @click='handleLogin()'>
                    <span class="button-text">登录</span>
                    <div class="button-glow"></div>
                </button>
            </form>

            <!-- 装饰性元素 -->
            <div class="decorative-elements">
                <div class="tech-line tech-line-1"></div>
                <div class="tech-line tech-line-2"></div>
                <div class="tech-circle tech-circle-1"></div>
                <div class="tech-circle tech-circle-2"></div>
                <div class="tech-circle tech-circle-3"></div>
            </div>
        </div>
    </div>
</template>

<script >
import apis from '@/api/apis';
import { getUUID } from '@/utils'
import constVal from '@/api/const';

export default {
    name: 'login',
    created () {
        this.getCaptcha()
    },
    data(){
        return{
            captchaPath: '',
            dataForm: {
                username: '',
                password: '',
                uuid: '',
                captcha: ''
            },
        }
    },
    methods:{
        handleLogin(){
            if(this.dataForm.username===''){
                this.$message.error("账户名不能为空")
                return
            }
            if(this.dataForm.password===''){
                this.$message.error("密码不能为空")
                return
            }

            apis.login(this.dataForm).then(res=>{
                if(res.code===0){
                    localStorage.setItem('username', this.dataForm.username);
                    this.$cookie.set('token', res.token)
                    this.$router.push('/dictionary');
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        // 获取验证码
        getCaptcha () {
            this.dataForm.uuid = getUUID()
            this.captchaPath = constVal.CaptchaInterface() +"?uuid="+this.dataForm.uuid;
        }
    }
}
</script>

<style>
.kaptcha{
    width: 30%;
    border-radius: 0.5rem;
    margin-left: 5px;
}
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: #0a0a0a;
    position: relative;
    overflow: hidden;
}

/* 背景网格 */
.grid-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(rgba(32, 128, 255, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(32, 128, 255, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    transform: perspective(500px) rotateX(60deg);
    transform-origin: center top;
    animation: grid-move 20s linear infinite;
}

/* 动态光效 */
.light-effect {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%,
    rgba(32, 128, 255, 0.1) 0%,
    transparent 50%);
    animation: light-pulse 4s ease-in-out infinite;
}

.login-box {
    width: 100%;
    max-width: 28rem;
    padding: 2.5rem;
    background: rgba(16, 16, 16, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 1rem;
    box-shadow: 0 0 30px rgba(32, 128, 255, 0.2);
    border: 1px solid rgba(32, 128, 255, 0.2);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.title-section {
    text-align: center;
    margin-bottom: 2.5rem;
    position: relative;
}

.title {
    font-size: 2.5rem;
    font-weight: bold;
    color: #fff;
    margin: 0;
    position: relative;
    display: inline-block;
}

.title-text {
    background: linear-gradient(90deg, #2080ff, #00ffff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    position: relative;
    z-index: 1;
}

.title-line {
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #2080ff, transparent);
    animation: line-glow 2s ease-in-out infinite;
}

.subtitle {
    color: #8a8a8a;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-wrapper {
    position: relative;
}

.input-border {
    position: relative;
    border: 1px solid rgba(32, 128, 255, 0.3);
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.input-border::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #2080ff, #00ffff);
    border-radius: 0.6rem;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.input-border:focus-within::before {
    opacity: 1;
}

.input-field {
    width: 100%;
    padding: 20px 0;
    padding-left: 10px;
    box-sizing: border-box;
    background: rgba(32, 32, 32, 0.8);
    border: none;
    border-radius: 0.5rem;
    color: #fff;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.input-field:focus {
    outline: none;
    background: rgba(32, 32, 32, 0.9);
}

.input-field::placeholder {
    color: #666;
}

.input-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-circle {
    width: 2rem;
    height: 2rem;
    background: rgba(32, 128, 255, 0.1);
    border-radius: 50%;
    position: absolute;
    animation: icon-pulse 2s ease-in-out infinite;
}

.icon {
    width: 1.25rem;
    height: 1.25rem;
    color: #2080ff;
    position: relative;
    z-index: 1;
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.custom-checkbox input {
    display: none;
}

.checkmark {
    width: 1.2rem;
    height: 1.2rem;
    border: 2px solid #2080ff;
    border-radius: 0.25rem;
    margin-right: 0.5rem;
    position: relative;
    transition: all 0.3s ease;
}

.custom-checkbox input:checked + .checkmark::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0.6rem;
    height: 0.6rem;
    background: #2080ff;
    border-radius: 0.1rem;
}

.checkbox-label {
    color: #8a8a8a;
    font-size: 0.9rem;
}

.forgot-password {
    color: #2080ff;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.forgot-password:hover {
    color: #00ffff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.login-button {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(45deg, #2080ff, #00ffff);
    border: none;
    border-radius: 0.5rem;
    color: white;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.button-text {
    position: relative;
    z-index: 1;
}

.button-glow {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: button-glow 2s linear infinite;
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(32, 128, 255, 0.4);
}

/* 装饰性元素 */
.decorative-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tech-line {
    position: absolute;
    background: linear-gradient(90deg, transparent, #2080ff, transparent);
    height: 1px;
    width: 100%;
    opacity: 0.3;
}

.tech-line-1 {
    top: 20%;
    animation: tech-line-move 3s ease-in-out infinite;
}

.tech-line-2 {
    bottom: 20%;
    animation: tech-line-move 3s ease-in-out infinite reverse;
}

.tech-circle {
    position: absolute;
    border: 1px solid rgba(32, 128, 255, 0.3);
    border-radius: 50%;
}

.tech-circle-1 {
    width: 100px;
    height: 100px;
    top: -50px;
    right: -50px;
    animation: circle-rotate 10s linear infinite;
}

.tech-circle-2 {
    width: 150px;
    height: 150px;
    bottom: -75px;
    left: -75px;
    animation: circle-rotate 15s linear infinite reverse;
}

.tech-circle-3 {
    width: 50px;
    height: 50px;
    top: 50%;
    right: -25px;
    animation: circle-rotate 8s linear infinite;
}

/* 动画关键帧 */
@keyframes grid-move {
    0% {
        transform: perspective(500px) rotateX(60deg) translateY(0);
    }
    100% {
        transform: perspective(500px) rotateX(60deg) translateY(50px);
    }
}

@keyframes light-pulse {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

@keyframes line-glow {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

@keyframes icon-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

@keyframes button-glow {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

@keyframes tech-line-move {
    0%, 100% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(100%);
    }
}

@keyframes circle-rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
</style>
